package controller

import (
	"context"
	"github.com/gogf/gf/v2/util/gconv"
	"lot_admin_api/api"
	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var User = cUser{}

type cUser struct{}

// UserList 获取用户列表
func (h *cUser) UserList(ctx context.Context, req *api.UserListReq) (res *model.UserListRes, err error) {
	res, err = service.User().UserList(ctx, req)
	return res, err
}

// UserInfo 通过用户Id获取用户详情
func (h *cUser) UserInfo(ctx context.Context, req *api.UserInfoReq) (res *model.UserInfoRes, err error) {
	res, err = service.User().SearchInfo(ctx, req.Id)
	return res, err
}

// GiveUserMoney 赠送用户金额
func (h *cUser) GiveUserMoney(ctx context.Context, req *api.GiveUserMoneyReq) (res *model.UserIdRes, err error) {
	var reqInfo *model.GiftAmount
	_ = gconv.Scan(req, &reqInfo)
	id, err := service.User().GiveUserMoney(ctx, reqInfo)
	res = &model.UserIdRes{
		Id: id,
	}
	return res, err
}

// GiveUserCoupon 赠送用户优惠券
func (h *cUser) GiveUserCoupon(ctx context.Context, req *api.GiveUserCouponReq) (res *model.UserInfoRes, err error) {
	res, err = service.User().SearchInfo(ctx, req.Id)
	return res, err
}
